#pragma once

#include "AriaVG.h"

template<typename T>
class A2DSubscriber;

class A2DDevice
{
public:
	enum NotifyCode 
	{
		NotifyCode_BeforeReset,
		NotifyCode_AfterReset,
	};
public:
	typedef boost::signals2::signal<void (NotifyCode code)> NotifySignal;

	NotifySignal OnNotify;
public:
	A2DDevice(void);
	~A2DDevice(void);

	bool Create(HWND window, bool windowed, CSize size, UINT refreshRate);
	IDirect3DDevice9* GetD3DDevice(void) const;	
private:
	CComPtr<IDirect3D9> m_d3d;
	D3DPRESENT_PARAMETERS m_d3dParams;
	CComPtr<IDirect3DDevice9> m_d3dDevice;
};

template<typename T>
class A2DSubscriber
{
public:
	static boost::shared_ptr<T> Create(A2DDevice &device)
	{
		boost::shared_ptr<T> subsc(new T(device));
		device.OnNotify.connect(A2DDevice::NotifySignal::slot_type(&A2DSubscriber::HandleNotify, subsc.get(), _1).track(subsc));
		return subsc;
	}

	virtual ~A2DSubscriber(void) {}
protected:
	A2DSubscriber(A2DDevice &device)
		: m_device(device)
	{
	}

	IDirect3DDevice9* GetD3DDevice( void ) const
	{
		return m_device.GetD3DDevice();
	}

	virtual void HandleNotify(A2DDevice::NotifyCode code) {}
private:
	A2DDevice &m_device;
};